package com.jianan.mis.app.basedata;

import static com.jianan.mis.util.ui.calendar.SWTCalendarWrapper.openCalendar;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.Set;

import org.eclipse.jface.dialogs.MessageDialog;
import org.eclipse.jface.viewers.ComboViewer;
import org.eclipse.jface.viewers.ISelectionChangedListener;
import org.eclipse.jface.viewers.IStructuredContentProvider;
import org.eclipse.jface.viewers.IStructuredSelection;
import org.eclipse.jface.viewers.LabelProvider;
import org.eclipse.jface.viewers.ListViewer;
import org.eclipse.jface.viewers.SelectionChangedEvent;
import org.eclipse.jface.viewers.Viewer;
import org.eclipse.swt.SWT;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.SelectionAdapter;
import org.eclipse.swt.events.SelectionEvent;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Button;
import org.eclipse.swt.widgets.Combo;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Text;
import org.eclipse.ui.part.ViewPart;

import com.jianan.mis.data.domain.Employee;
import com.jianan.mis.data.domain.Group;
import com.jianan.mis.service.EmployeeService;
import com.jianan.mis.service.GroupService;
import com.jianan.mis.sys.IMessageKeys;
import com.jianan.mis.sys.SpringBeanFactory;
import com.jianan.mis.util.RegularUtils;
import com.jianan.mis.util.StringUtils;

@SuppressWarnings("unchecked")
public class EmployeeView extends ViewPart {

	private Text txtLeaveDate;
	private Text txtEnterDate;
	class EmployeeListLabelProvider extends LabelProvider {
		public String getText(Object element) {
			Employee employee = (Employee) element;
			return employee.getName();
		}
		public Image getImage(Object element) {
			return null;
		}
	}
	class EmployeeContentProvider implements IStructuredContentProvider {
		public Object[] getElements(Object inputElement) {
			return ((List) inputElement).toArray();
		}
		public void dispose() {
		}
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		}
	}
	class GroupListLabelProvider extends LabelProvider {
		public String getText(Object element) {
			Group group = (Group) element;
			return group.getName();
		}
		public Image getImage(Object element) {
			return null;
		}
	}
	class GroupContentProvider implements IStructuredContentProvider {
		public Object[] getElements(Object inputElement) {
			return ((Set) inputElement).toArray();
		}
		public void dispose() {
		}
		public void inputChanged(Viewer viewer, Object oldInput, Object newInput) {
		}
	}
	
	private ComboViewer employeeComboViewer;
	private ListViewer allListViewer;
	private ListViewer selectedListViewer;
	private org.eclipse.swt.widgets.List selectedList;
	private org.eclipse.swt.widgets.List allList;
	private Text txtYibaoNo;
	private Text txtShebaoNo;
	private Text txtMail;
	private Text txtPhone;
	private Text txtBirthday;
	private Text txtPasswordConfirm;
	private Text txtPassword;
	private Text txtUsername;
	private Text txtName;
	private Combo combo;
	public static final String ID = "com.jianan.mis.app.basedata.EmployeeView"; //$NON-NLS-1$

	final SimpleDateFormat simpleDateFormat = new SimpleDateFormat("MM月dd日");
	
	final SimpleDateFormat simpleDateFormat1 = new SimpleDateFormat("yyyy年MM月dd日");
	
	private GroupService groupService;
	
	private EmployeeService employeeService;
	
	private Employee currentEmployee;

	/**
	 * Create contents of the view part
	 * @param parent
	 */
	@Override
	public void createPartControl(Composite parent) {
		
		if(!initializeServices()) {
			MessageDialog.openError(getViewSite().getShell(),
					IMessageKeys.OPEN_VIEW_FAIL, IMessageKeys.SERVICE_UNAVAILABLE);
			return;
		}
		
		Composite container = new Composite(parent, SWT.NONE);
		final GridLayout gridLayout = new GridLayout();
		gridLayout.makeColumnsEqualWidth = true;
		gridLayout.numColumns = 6;
		container.setLayout(gridLayout);

		final Label label = new Label(container, SWT.NONE);
		label.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
		label.setText("员工选择:");

		employeeComboViewer = new ComboViewer(container, SWT.READ_ONLY);
		employeeComboViewer.addSelectionChangedListener(new ISelectionChangedListener() {
			public void selectionChanged(final SelectionChangedEvent event) {
				IStructuredSelection selection = (IStructuredSelection) event.getSelection();
				currentEmployee = (Employee) selection.getFirstElement();
				txtName.setText(currentEmployee.getName());
				txtUsername.setText(currentEmployee.getUsername());
				//txtPassword.setText(currentEmployee.getPassword());
				//txtPasswordConfirm.setText(currentEmployee.getPassword());
				txtBirthday.setText(simpleDateFormat.format(currentEmployee.getBirthday()));
				if(currentEmployee.getEnterDate() != null)
					txtEnterDate.setText(simpleDateFormat1.format(currentEmployee.getEnterDate()));
				else
					txtEnterDate.setText("");
				if(currentEmployee.getLeaveDate() != null)
					txtLeaveDate.setText(simpleDateFormat1.format(currentEmployee.getLeaveDate()));
				else
					txtLeaveDate.setText("");
				txtPhone.setText(currentEmployee.getPhone());
				if (currentEmployee.getMail() != null)
					txtMail.setText(currentEmployee.getMail());
				else
					txtMail.setText("");
				if (currentEmployee.getShebaoNo() != null)
					txtShebaoNo.setText(currentEmployee.getShebaoNo());
				if (currentEmployee.getYibaoNo() != null)
					txtYibaoNo.setText(currentEmployee.getYibaoNo());
				selectedListViewer.setInput(currentEmployee.getGroups());
			}
		});
		employeeComboViewer.setContentProvider(new EmployeeContentProvider());
		employeeComboViewer.setLabelProvider(new EmployeeListLabelProvider());
		combo = employeeComboViewer.getCombo();
		combo.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 5, 1));
		employeeComboViewer.setInput(employeeService.getAll());
		
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);

		final Label label_1 = new Label(container, SWT.NONE);
		label_1.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
		label_1.setText("姓名:");

		txtName = new Text(container, SWT.BORDER);
		final GridData gd_txtName = new GridData(SWT.LEFT, SWT.CENTER, true, false, 5, 1);
		gd_txtName.widthHint = 89;
		txtName.setLayoutData(gd_txtName);

		final Label label_2 = new Label(container, SWT.NONE);
		label_2.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
		label_2.setText("用户名:");

		txtUsername = new Text(container, SWT.BORDER);
		final GridData gd_txtUsername = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		gd_txtUsername.widthHint = 96;
		txtUsername.setLayoutData(gd_txtUsername);

		final Label label_4 = new Label(container, SWT.NONE);
		label_4.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false));
		label_4.setText("用户名长度不得超过20位");

		final Button btnCheckUsername = new Button(container, SWT.NONE);
		btnCheckUsername.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if((currentEmployee != null && txtUsername.getText().equals(currentEmployee.getUsername())) || checkUsername()) {
					MessageDialog.openInformation(e.display.getActiveShell(), 
							IMessageKeys.INFORMATION, "用户名有效!");
				}
			}
		});
		final GridData gd_btnCheckUsername = new GridData(SWT.LEFT, SWT.CENTER, true, false, 3, 1);
		btnCheckUsername.setLayoutData(gd_btnCheckUsername);
		btnCheckUsername.setText("检查用户名有效性");

		final Label label_3 = new Label(container, SWT.NONE);
		label_3.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
		label_3.setText("密码设置:");

		txtPassword = new Text(container, SWT.BORDER | SWT.PASSWORD);
		final GridData gd_txtPassword = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		gd_txtPassword.widthHint = 140;
		txtPassword.setLayoutData(gd_txtPassword);

		final Label label_6 = new Label(container, SWT.NONE);
		label_6.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false, 4, 1));
		label_6.setText("密码长度不得超过10位");

		final Label label_5 = new Label(container, SWT.NONE);
		label_5.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false));
		label_5.setText("密码确认:");

		txtPasswordConfirm = new Text(container, SWT.BORDER | SWT.PASSWORD);
		final GridData gd_txtPasswordConfirm = new GridData(SWT.LEFT, SWT.CENTER, true, false, 5, 1);
		gd_txtPasswordConfirm.widthHint = 140;
		txtPasswordConfirm.setLayoutData(gd_txtPasswordConfirm);

		final Label label_7 = new Label(container, SWT.NONE);
		label_7.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_7.setText("生日:");

		txtBirthday = new Text(container, SWT.READ_ONLY | SWT.BORDER);
		txtBirthday.setEditable(false);
		txtBirthday.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				openCalendar(e, txtBirthday, simpleDateFormat);
			}
		});
		final GridData gd_txtBirthday = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		gd_txtBirthday.widthHint = 90;
		txtBirthday.setLayoutData(gd_txtBirthday);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);

		final Label label_12 = new Label(container, SWT.NONE);
		label_12.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_12.setText("入职时间:");

		txtEnterDate = new Text(container, SWT.READ_ONLY | SWT.BORDER);
		txtEnterDate.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				openCalendar(e, txtEnterDate, simpleDateFormat1);
			}
		});
		final GridData gd_txtEnterDate = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		gd_txtEnterDate.widthHint = 90;
		txtEnterDate.setLayoutData(gd_txtEnterDate);

		final Label label_13 = new Label(container, SWT.NONE);
		label_13.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_13.setText("离职时间:");

		txtLeaveDate = new Text(container, SWT.READ_ONLY | SWT.BORDER);
		txtLeaveDate.addMouseListener(new MouseAdapter() {
			public void mouseDown(final MouseEvent e) {
				openCalendar(e, txtLeaveDate, simpleDateFormat1);
			}
		});
		final GridData gd_txtLeaveDate = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		gd_txtLeaveDate.widthHint = 90;
		txtLeaveDate.setLayoutData(gd_txtLeaveDate);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);

		final Label label_8 = new Label(container, SWT.NONE);
		label_8.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_8.setText("联系电话:");

		txtPhone = new Text(container, SWT.BORDER);
		final GridData gd_txtPhone = new GridData(SWT.LEFT, SWT.CENTER, true, false);
		gd_txtPhone.widthHint = 110;
		txtPhone.setLayoutData(gd_txtPhone);

		final Label label_9 = new Label(container, SWT.NONE);
		label_9.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_9.setText("邮箱:");

		txtMail = new Text(container, SWT.BORDER);
		final GridData gd_txtMail = new GridData(SWT.LEFT, SWT.CENTER, true, false, 3, 1);
		gd_txtMail.widthHint = 150;
		txtMail.setLayoutData(gd_txtMail);

		final Label label_10 = new Label(container, SWT.NONE);
		label_10.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_10.setText("社保档案号:");

		txtShebaoNo = new Text(container, SWT.BORDER);
		final GridData gd_txtShebaoNo = new GridData(SWT.LEFT, SWT.CENTER, true, false, 5, 1);
		gd_txtShebaoNo.widthHint = 280;
		txtShebaoNo.setLayoutData(gd_txtShebaoNo);

		final Label label_11 = new Label(container, SWT.NONE);
		label_11.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_11.setText("医保档案号:");

		txtYibaoNo = new Text(container, SWT.BORDER);
		final GridData gd_txtYibaoNo = new GridData(SWT.LEFT, SWT.CENTER, true, false, 5, 1);
		gd_txtYibaoNo.widthHint = 280;
		txtYibaoNo.setLayoutData(gd_txtYibaoNo);

		final Label label_14 = new Label(container, SWT.NONE);
		label_14.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, false, false));
		label_14.setText("选择所属组别:");
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);

		allListViewer = new ListViewer(container, SWT.V_SCROLL | SWT.MULTI | SWT.H_SCROLL | SWT.BORDER);
		allListViewer.setLabelProvider(new GroupListLabelProvider());
		allListViewer.setContentProvider(new GroupContentProvider());
		allList = allListViewer.getList();
		final GridData gd_list = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 5);
		gd_list.heightHint = 130;
		gd_list.widthHint = 100;
		allList.setLayoutData(gd_list);
		Set<Group> set = new HashSet<Group>(groupService.getAll());
		allListViewer.setInput(set);
		
		new Label(container, SWT.NONE);

		selectedListViewer = new ListViewer(container, SWT.V_SCROLL | SWT.MULTI | SWT.H_SCROLL | SWT.BORDER);
		selectedListViewer.setLabelProvider(new GroupListLabelProvider());
		selectedListViewer.setContentProvider(new GroupContentProvider());
		selectedList = selectedListViewer.getList();
		final GridData gd_list_1 = new GridData(SWT.LEFT, SWT.CENTER, false, false, 1, 5);
		gd_list_1.heightHint = 130;
		gd_list_1.widthHint = 100;
		selectedList.setLayoutData(gd_list_1);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);

		final Button btnAddGroups = new Button(container, SWT.NONE);
		btnAddGroups.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				// 取得选择要添加的group
				IStructuredSelection selections = (IStructuredSelection) allListViewer.getSelection();
				Iterator iterator = selections.iterator();
				Set<Group> selectedGroups;
				if (selectedListViewer.getInput() != null)
					selectedGroups = (Set<Group>) selectedListViewer.getInput();
				else
					selectedGroups = new HashSet<Group>();
				while(iterator.hasNext()) {
					Group group = (Group) iterator.next();
					selectedGroups.add(group);
				}
				selectedListViewer.setInput(selectedGroups);
			}
		});
		final GridData gd_btnAddGroups = new GridData(SWT.CENTER, SWT.CENTER, false, false);
		gd_btnAddGroups.widthHint = 70;
		btnAddGroups.setLayoutData(gd_btnAddGroups);
		btnAddGroups.setText("添加组别");
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);

		final Button btnDelGroups = new Button(container, SWT.NONE);
		btnDelGroups.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				// 取得选择要移除的group
				IStructuredSelection selections = (IStructuredSelection) selectedListViewer.getSelection();
				Iterator iterator = selections.iterator();
				Set<Group> selectedGroups = (Set<Group>) selectedListViewer.getInput();
				while(iterator.hasNext()) {
					Group group = (Group) iterator.next();
					selectedGroups.remove(group);
				}
				selectedListViewer.setInput(selectedGroups);
			}
		});
		final GridData gd_btnDelGroups = new GridData(SWT.CENTER, SWT.CENTER, false, false);
		gd_btnDelGroups.widthHint = 70;
		btnDelGroups.setLayoutData(gd_btnDelGroups);
		btnDelGroups.setText("移除组别");
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);

		final Button btnSave = new Button(container, SWT.NONE);
		btnSave.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if (checkInfo(false)) {
					Employee employee = new Employee();
					fillEmployeeFields(employee);
					try {
						employeeService.save(employee);
						reset();
						MessageDialog.openInformation(e.display.getActiveShell(), 
								IMessageKeys.SUCCESS, "新增员工信息成功!");
					} catch(Exception ex) {
						MessageDialog.openError(e.display.getActiveShell(),
								IMessageKeys.FAIL, ex.getMessage());
						return;
					}
				}
			}
		});
		final GridData gd_btnSave = new GridData(SWT.CENTER, SWT.CENTER, false, false);
		gd_btnSave.widthHint = 70;
		btnSave.setLayoutData(gd_btnSave);
		btnSave.setText("新增员工");

		final Button btnUpdate = new Button(container, SWT.NONE);
		btnUpdate.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if(currentEmployee == null) {
					MessageDialog.openInformation(e.display.getActiveShell(), 
							IMessageKeys.FAIL, "请选择一个员工!");
					return;
				}
				if (checkInfo(true)) {
					fillEmployeeFields(currentEmployee);
					try {
						employeeService.update(currentEmployee);
						reset();
						MessageDialog.openInformation(e.display.getActiveShell(), 
								IMessageKeys.SUCCESS, "更新员工信息成功!");
					} catch(Exception ex) {
						MessageDialog.openError(e.display.getActiveShell(),
								IMessageKeys.FAIL, ex.getMessage());
						return;
					}
				}
			}
		});
		btnUpdate.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
		btnUpdate.setText("更新员工信息");

		final Button btnRemove = new Button(container, SWT.NONE);
		btnRemove.addSelectionListener(new SelectionAdapter() {
			public void widgetSelected(final SelectionEvent e) {
				if(currentEmployee == null) {
					MessageDialog.openInformation(e.display.getActiveShell(), 
							IMessageKeys.FAIL, "请选择一个员工!");
					return;
				}
				if(MessageDialog.openConfirm(e.display.getActiveShell(), 
						IMessageKeys.CONFIRM, "确认删除该员工吗?")) {
					try {
						employeeService.remove(currentEmployee);
						reset();
						MessageDialog.openInformation(e.display.getActiveShell(), 
								IMessageKeys.SUCCESS, "删除员工信息成功!");
					} catch(Exception ex) {
						MessageDialog.openError(e.display.getActiveShell(),
								IMessageKeys.FAIL, ex.getMessage());
					}
				}
			}
		});
		btnRemove.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
		btnRemove.setText("删除员工");
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);
		new Label(container, SWT.NONE);

		//
		createActions();
		initializeToolBar();
		initializeMenu();
	}
	
	private boolean initializeServices() {
		groupService = (GroupService) SpringBeanFactory.getBean("groupService");
		if(groupService == null) {
			return false;
		}
		employeeService = (EmployeeService) SpringBeanFactory.getBean("employeeService");
		if(employeeService == null) {
			return false;
		}
		return true;
	}
	
	private void reset() {
		txtName.setText("");
		txtUsername.setText("");
		txtPassword.setText("");
		txtPasswordConfirm.setText("");
		txtBirthday.setText("");
		txtEnterDate.setText("");
		txtLeaveDate.setText("");
		txtPhone.setText("");
		txtMail.setText("");
		txtShebaoNo.setText("");
		txtYibaoNo.setText("");
		allListViewer.setSelection(null);
		selectedListViewer.setInput(null);
		employeeComboViewer.setInput(employeeService.getAll());
		currentEmployee = null;
	}
	
	private void fillEmployeeFields(Employee employee) {
		employee.setName(txtName.getText());
		employee.setUsername(txtUsername.getText());
		if(StringUtils.isEmpty(employee.getPassword()) ||
				StringUtils.isNotEmpty(txtPassword.getText())) {
			employee.setPassword(txtPassword.getText());
		}
		try {
			employee.setBirthday(simpleDateFormat.parse(txtBirthday.getText()));
		} catch (ParseException ex) {
			ex.printStackTrace();
		}
		if(StringUtils.isNotEmpty(txtEnterDate.getText())) {
			try {
				employee.setEnterDate(simpleDateFormat1.parse(txtEnterDate.getText()));
			} catch (ParseException ex) {
				ex.printStackTrace();
			}
		} else {
			employee.setEnterDate(null);
		}
		if(StringUtils.isNotEmpty(txtLeaveDate.getText())) {
			try {
				employee.setLeaveDate(simpleDateFormat1.parse(txtLeaveDate.getText()));
			} catch (ParseException ex) {
				ex.printStackTrace();
			}
		} else {
			employee.setLeaveDate(null);
		}
		employee.setPhone(txtPhone.getText());
		employee.setMail(txtMail.getText());
		employee.setShebaoNo(txtShebaoNo.getText());
		employee.setYibaoNo(txtYibaoNo.getText());
		employee.setGroups((Set<Group>) selectedListViewer.getInput());
	}
	
	private boolean checkUsername() {
		if(StringUtils.isEmpty(txtUsername.getText())) {
			MessageDialog.openError(getViewSite().getWorkbenchWindow().getShell(), 
					IMessageKeys.INFORMATION, "请输入用户名!");
			return false;
		}
		if(txtUsername.getText().length() > 20) {
			MessageDialog.openError(getViewSite().getWorkbenchWindow().getShell(), 
					IMessageKeys.INFORMATION, "用户名长度不得超过20位!");
			return false;
		}
		if(StringUtils.isNotEmpty(txtUsername.getText())) {
			if(employeeService.findByUsername(txtUsername.getText()) != null) {
				MessageDialog.openError(getViewSite().getWorkbenchWindow().getShell(), 
						IMessageKeys.INFORMATION, "该用户名已被占用!");
				return false;
			}
		}
		return true;
	}
	
	private boolean checkInfo(boolean update) {
		if(StringUtils.isEmpty(txtName.getText())) {
			MessageDialog.openError(getViewSite().getWorkbenchWindow().getShell(), 
					IMessageKeys.INFORMATION, "请输入姓名!");
			return false;
		}
		if(!(update && txtUsername.getText().equals(currentEmployee.getUsername())) && !checkUsername()) {
			return false;
		}
		if(update && StringUtils.isNotEmpty(txtPassword.getText())) {
			if(StringUtils.isEmpty(txtPassword.getText())) {
				MessageDialog.openError(getViewSite().getWorkbenchWindow().getShell(), 
						IMessageKeys.INFORMATION, "请输入密码!");
				return false;
			}
			if(txtPassword.getText().length() > 10) {
				MessageDialog.openError(getViewSite().getWorkbenchWindow().getShell(), 
						IMessageKeys.INFORMATION, "密码长度不得超过10位!");
				return false;
			}
			if(!txtPassword.getText().equals(txtPasswordConfirm.getText())) {
				MessageDialog.openError(getViewSite().getWorkbenchWindow().getShell(), 
						IMessageKeys.INFORMATION, "密码确认不一致!");
				return false;
			}
		}
		if(StringUtils.isEmpty(txtBirthday.getText())) {
			MessageDialog.openError(getViewSite().getWorkbenchWindow().getShell(), 
					IMessageKeys.INFORMATION, "请输入出生年月日!");
			return false;
		}
		if (StringUtils.isNotEmpty(txtMail.getText()) && !RegularUtils.emailCheck(txtMail.getText().trim())) {
			MessageDialog.openError(getViewSite().getWorkbenchWindow().getShell(),
					IMessageKeys.INFORMATION, "E-mail格式输入不正确,请重新输入!");
			txtMail.setFocus();
			return false;
		}
		return true;
	}

	/**
	 * Create the actions
	 */
	private void createActions() {
		// Create the actions
	}

	/**
	 * Initialize the toolbar
	 */
	private void initializeToolBar() {
	}

	/**
	 * Initialize the menu
	 */
	private void initializeMenu() {
	}

	@Override
	public void setFocus() {
		// Set the focus
	}

}
